<template>
  <div class="list-table">
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('项目名称')" prop="dealName">
        <el-input v-model="queryParams.dealName" :placeholder="$t('项目名称')" show-word-limit maxlength="100" />
      </el-form-item>
      <el-form-item :label="$t('公司名称')" prop="companyName">
        <el-input v-model="queryParams.companyName" :placeholder="$t('公司名称')" show-word-limit maxlength="100" />
      </el-form-item>
      <el-form-item :label="$t('状态')" prop="companyName">
        <el-select v-model="queryParams.status" :placeholder="$t('状态')">
          <el-option :label="$t('待复核')" value="待复核" />
          <el-option :label="$t('已复核')" value="已复核" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="dealIndicatorDataList" border tooltip-effect="darkTable">
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('公司名称')" align="center" prop="dealName" />
      <el-table-column :label="$t('项目名称')" align="center" prop="companyName" />
      <el-table-column :label="$t('项目负责人')" align="center" prop="nickName" />
      <el-table-column :label="$t('状态')" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status === '已复核'" style="color: green">{{ scope.row.status }}</span>
          <span v-else-if="scope.row.status === '待复核'" style="color: orange">{{ scope.row.status }}</span>
          <span v-else>{{ scope.row.status }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['deal:indicator:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >
            <span v-if="scope.row.status === '已复核'">{{ $t('查看') }}</span>
            <span v-else-if="scope.row.status === '待复核' || scope.row.status === '已驳回'">{{ $t('复核') }}</span>
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改运营指标数据维护对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" :fullscreen="true" :destroy-on-close="true" append-to-body @close="getList()">
      <leaderEvaluate ref="leaderEvaluate" />
    </el-dialog>
  </div>
</template>

<script>
import {
  auditPage
} from '@/api/deal/indicator/evaluate/dealIndicatorEvaluate.js'
import leaderEvaluate from '@/views/deal/report/leaderEvaluate.vue'

export default {
  components: {
    leaderEvaluate
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 运营指标数据维护表格数据
      dealIndicatorDataList: [],
      // 弹出层标题
      title: '运营指标数据填写情况',
      // 是否显示弹出层
      formOpen: false,
      // 查询参数
      queryParams: {
        dealName: undefined,
        companyName: undefined,
        status: undefined,
        pageNum: 1,
        pageSize: 10
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询运营指标数据维护列表 */
    getList() {
      this.loading = true
      auditPage(this.queryParams).then(response => {
        this.dealIndicatorDataList = response.rows
        this.total = response.total
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: undefined,
        companyId: undefined,
        startYear: undefined,
        forecastYear: undefined,
        cycle: undefined,
        remark: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        delFlag: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.status = undefined
      this.resetForm('queryForm')
      this.queryHandle()
    },
    /** 修改按钮操作 */
    updateHandle(row) {
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.leaderEvaluate.parentStatus = row.status
        this.$refs.leaderEvaluate.currencyDealId = row.dealId
        this.$refs.leaderEvaluate.currencyCompanyId = row.companyId
        this.$refs.leaderEvaluate.isAuditPage = true
        this.$refs.leaderEvaluate.parentChoiceEvaluate = row.report
        this.$refs.leaderEvaluate.init(row)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
/deep/.dialogForm .el-dialog__body {
  overflow: auto;
}
</style>
